package com.kazalan.domain.document;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import com.kazalan.domain.BaseObject;

public class Document extends BaseObject implements Serializable {

	private static final long serialVersionUID = 4491847743166149089L;

	private DocumentAggregate documentAggregate;

	private Language language;

	private String name;

	private String description;

	private String text;

	private List<Section> sections;

	public Document() {
		super();
		this.sections = new LinkedList<Section>();
	}

	public DocumentAggregate getDocumentAggregate() {
		return documentAggregate;
	}

	public void setDocumentAggregate(DocumentAggregate documentAggregate) {
		this.documentAggregate = documentAggregate;
	}

	public void setLanguage(Language language) {
		this.language = language;
	}

	public Language getLanguage() {
		return language;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void addSection(Section section) {
		this.sections.add(section);
	}

	public void setSections(List<Section> sections) {
		this.sections = sections;
	}

	public List<Section> getSections() {
		return sections;
	}

	@Override
	public String toString() {
		return new StringBuilder().append(getId()).append(" " + name)
				.append(" Sections : " + this.sections).append("\r").toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime
				* result
				+ ((documentAggregate == null) ? 0 : documentAggregate
						.hashCode());
		result = prime * result
				+ ((language == null) ? 0 : language.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((text == null) ? 0 : text.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Document other = (Document) obj;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (documentAggregate == null) {
			if (other.documentAggregate != null)
				return false;
		} else if (!documentAggregate.equals(other.documentAggregate))
			return false;
		if (language == null) {
			if (other.language != null)
				return false;
		} else if (!language.equals(other.language))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (text == null) {
			if (other.text != null)
				return false;
		} else if (!text.equals(other.text))
			return false;
		return true;
	}

}
